package com.jingxing.controller;

import com.jingxing.config.ApiResult;
import com.jingxing.config.UserLoginToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@RestController
@RequestMapping("/rewardReceive")
@Api(value = "API", tags = {"领奖相关"})
@UserLoginToken
public class RewardReceiveController {
    @Autowired
    private RestTemplate restTemplate;

    private static final String URL_20001 = "http://JINGXINGPROJECT-SERVER";

    @PostMapping("/consume")
    @ApiOperation("使用领奖次数")
    @Transactional
    public ApiResult consume(String playerId, String prizeId) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("playerId", playerId);
        requestEntity.add("prizeId", prizeId);
        return restTemplate.postForObject(URL_20001 + "/rewardReceive/consume", requestEntity, ApiResult.class);
    }

    @PostMapping("/getRewardReceives")
    @ApiOperation("获取奖品领取信息")
    public ApiResult getRewardReceives(String playerName, String prizeName) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("playerName", playerName);
        requestEntity.add("prizeName", prizeName);
        return restTemplate.postForObject(URL_20001 + "/rewardReceive/getRewardReceives", requestEntity, ApiResult.class);
    }

    @PostMapping("/updateRewardReceive")
    @ApiOperation("修改领奖次数")
    public ApiResult updateRewardReceive(String id, Integer type, String updateBy) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("id", id);
        requestEntity.add("type", type);
        requestEntity.add("updateBy", updateBy);
        return restTemplate.postForObject(URL_20001 + "/rewardReceive/updateRewardReceive", requestEntity, ApiResult.class);
    }


}
